using UnityEngine;
using UnityEngine.UI;

/****************************************************
// 功能：
// | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
// | Copyright (c) 2021-2025 聊来 All rights reserved.
// | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">聊来</a> )
// | @Author: 贯彻己道的云 <18970881148@qq.com>
// | DateTime: 2025/3/4 18:17:12
*****************************************************/

public class MatchWindow : BaseWindow
{

    private Text t1;
    private Text t2;

    private float currentTime = 0;
    private int time;
    
    private void Awake()
    {
        t1 = FindChildTransform(transform, "t1").GetComponent<Text>();
        t2 = FindChildTransform(transform, "t2").GetComponent<Text>();
    }

    private void Update()
    {
        currentTime += Time.deltaTime;
        if (time >= currentTime)
        {
            SetText(t2, Tool.ConvertSecondsToTime((int) currentTime));
        }
        else
        {
            MatchController.Instance.ResetOperation();
        }
        
    }

    protected override void InitWindows()
    {
        base.InitWindows();
    }

    protected override void OnOpen(object arg)
    {
        base.OnOpen(arg);
        
        time = (int) arg;
        SetText(t1, $"匹配时间 {Tool.ConvertSecondsToTime(time)}");
    }

    public void BackHomeButton()
    {
        MatchController.Instance.BackHome();
    }

    public void CancelButton()
    {
        MatchController.Instance.ResetOperation();
    }
}
